<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>项目编辑</title>

    <link rel="stylesheet" href="http://cdn.viptool.cn/lib/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="http://cdn.viptool.cn/lib/animate.css/2.1.1/animate.min.css" rel="stylesheet">

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
</head>

<body class="gray-bg">
<form id="saveForm">
    <div class="wrapper wrapper-content animated fadeInRight tooltip-demo" th:object="${config}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title" style="min-height: 60px;">
                        <h5>提现配置</h5>
                    </div>

                    <div class="ibox-content">
                        <div class="panel-body form-horizontal">
                            <div class="form-group form-inline">
                                <label class="col-sm-2 control-label">*提现方式：</label>
                                <div class="col-sm-10">
                                    <th:block th:each="channelType:${channelTypes}">
                                        <input type="checkbox" name="chkChannelType" id="chkChannel_0" th:id="${'chkChannelType_'+channelType.code}" th:value="${channelType.code}"/>
                                        <label for="chkChannel_0" class="control-label" th:for="${'chkChannelType_'+channelType.code}" th:text="${channelType.desc}">银行卡</label>
                                    </th:block>
                                </div>
                                <input type="hidden" id="hdChannelTypes" th:value="*{channelTypes}"/>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group form-inline">
                                <label class="col-sm-2 control-label">*手续费率：</label>
                                <div class="col-sm-10">
                                    <input type="text" required th:value="*{feeRate}" name="feeRate" id="feeRate" class="form-control input-sm input-s only-float" placeholder="手续费率"/>%
                                </div>
                            </div>
                            <!--<div class="hr-line-dashed"></div>-->
                            <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 control-label">*最小手续费：</label>-->
                            <!--<div class="col-sm-10">-->
                            <!--<input type="text" required th:value="*{minFeeAmount}" name="minFeeAmount" id="minFeeAmount" class="form-control input-sm input-s only-float" placeholder="最小手续费"/>-->
                            <!--</div>-->
                            <!--</div>-->
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">*起提金额：</label>
                                <div class="col-sm-10">
                                    <input type="text" required th:value="*{baseAmount}" name="baseAmount" id="baseAmount" class="only-float form-control input-sm input-s" placeholder="起提金额"/>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">*提现倍数：</label>
                                <div class="col-sm-10">
                                    <input type="text" required th:value="*{multiple}" name="multiple" id="multiple" class="only-num form-control input-sm input-s" placeholder="起提金额"/>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">*提现上限：</label>
                                <div class="col-sm-10">
                                    <input type="text" required th:value="*{upperLimit}" name="upperLimit" id="upperLimit" class="only-float form-control input-sm input-s" placeholder="提现上限"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="ibox float-e-margins m-b-none">
                                        <div class="ibox-content no-borders text-center">
                                            <button type="submit" class="btn btn-primary m-b-none m-l">保存
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</form>

<!--基础框架js-->
<script src="http://cdn.viptool.cn/lib/jquery/2.2.4/jquery.min.js"></script>
<script src="http://cdn.viptool.cn/lib/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316"></script>

<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="http://cdn.viptool.cn/lib/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="http://cdn.viptool.cn/lib/jquery-validate/1.17.0/localization/messages_zh.min.js"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const apiSaveUri = /*[[@{/withdrawal/config/save}]]*/  "";
</script>
<script type="text/javascript">
    $(function () {
        let channelTypes = $.trim($('#hdChannelTypes').val());
        if (channelTypes.length > 0) {
            let channelTypeArray = channelTypes.split(',');
            $.each(channelTypeArray, function (o, item) {
                $("#chkChannelType_" + item).prop("checked", "checked");
            });
        }
    });

    $("#saveForm").validateCallback(function () {
        configHandler.save();
    });

    var configHandler = {
        save: function () {
            let channelTypes = ""
            $("input[name=chkChannelType]:checked").each(function () {
                channelTypes += $(this).val() + ",";
            });
            channelTypes = channelTypes.substring(0, channelTypes.length - 1);
            let feeRate = $.trim($("#feeRate").val());
            let minFeeAmount = $.trim($("#minFeeAmount").val());
            let baseAmount = $.trim($("#baseAmount").val());
            let multiple = $.trim($("#multiple").val());
            let upperLimit = $.trim($("#upperLimit").val());

            let requestData = {
                channelTypes: channelTypes,
                feeRate: feeRate,
                minFeeAmount: minFeeAmount,
                baseAmount: baseAmount,
                multiple: multiple,
                upperLimit: upperLimit
            };

            hot.ajax(apiSaveUri, requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("保存成功", function () {
                        window.location.reload();
                    });
                } else {
                    hot.tip.error("保存失败--", apiResult.resultMsg);
                }
            }, function () {
            }, "post", 300);
        }
    }
</script>
</body>

</html>
